<script setup>
import { ref } from 'vue'
const myVal = ref('')
let timer = null
const change = () => {
  timer && clearTimeout(timer)
  timer = setTimeout(() => {
    console.log(2)
  }, 1000)
}
let moveTimer = null
const mousemove = () => {
  if (moveTimer) return
  moveTimer = setTimeout(() => {
    moveTimer = null
  }, 2000)
}
new Promise((resolve, reject) => {
  setTimeout(() => {}, 2000)
})
  .then((data) => {
    console.log(data)
  })
  .catch((err) => {})
function* getData() {
  console.log('准备执行')
  yield console.log(3)
  yield console.log(4)
  console.log('执行完毕')
}
const generator = getData()
generator.next()
generator.next()
generator.next()
const getData1 = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('ok')
    }, 2000)
  })
}
const initData = async () => {
  console.log('开始请求')
  const data = await getData1()
  console.log(data)
  console.log('请求完毕')
}
initData()

const p1 = Promise.resolve({
  then: (resolve) => {
    setTimeout(() => {
      resolve(1)
    }, 1200)
  }
})
const p2 = Promise.resolve({
  then: (resolve) => {
    setTimeout(() => {
      resolve(2)
    }, 1000)
  }
})

Promise.race([p1, p2]).then((data) => {
  console.log(data) // [2]
})
</script>
<template>
  <el-input v-model="myVal" @input="change"></el-input>
  <div class="size-[400px] bg-[#eee]" @mousemove="mousemove"></div>
</template>
